package com.gitee.wsl.ext.map


// Generally these operations are meant to be used with ordered maps. We do not require
// explicitly stating that they are LinkedHashMap since Iterable<Pair<K, V>>.toMap()
// in Kotlin automatically uses a LinkedHashMap if there is more than one element.
// If that changes in the future this decision can be reconsidered.

fun <K, V, R> Map<K, V>.zipWith(m2: Map<K, V>, f: (K, V, V?) -> R?): List<R> =
    this.toList().mapNotNull { (k, v) -> f(k, v, m2[k]) }

fun <K, V, R> Map<K, V>.outerZipWith(m2: Map<K, V>, f: (K, V?, V?) -> R?): LinkedHashSet<R> =
    LinkedHashSet((this.keys + m2.keys).mapNotNull { k -> f(k, this[k], m2[k]) })

